package com.student.education.service.impl;

import com.student.education.dao.RoleDao;
import com.student.education.entity.Role;
import com.student.education.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("roleService")
public class RoleServiceImpl implements RoleService {

    @Resource
    private RoleDao roleDao;

    @Override
    public List<Role> queryAll(Role vo) {
        return roleDao.queryAll(vo);
    }

    @Override
    public int update(Role vo) {
        String name = vo.getRoleName();

        int j = roleDao.queryOne(name);
        if (j == 1) {
            return 0;
        } else {
            int i = roleDao.update(vo);
            return i;
        }
    }

    @Override
    public int delete(Integer id) {
        int i = roleDao.delete(id);
        return i;
    }

    @Override
    public int add(Role vo) {
        String name = vo.getRoleName();
        int j = roleDao.queryOne(name);
        if (j == 1) {
            return 0;
        } else {

            int i = roleDao.add(vo);
            return i;
        }
    }
}
